﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Text;

namespace HQWeb.Login
{
    public partial class left : BasePage
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            VerdictIsLogin();
            if (!IsPostBack)
            {
                BLL.SysManage.T_PUB_USERROLE role_UserBll = new BLL.SysManage.T_PUB_USERROLE();
                string strUserID = Session["USER_ID"].ToString();
                List<Model.SysManage.T_PUB_USERROLE> modelList = role_UserBll.GetUserRoleList(strUserID);
                if (Universal.CommonMethod.checkRole(modelList))
                {
                    Session["IsAll"] = true;
                }
                else
                {
                    Session["IsAll"] = false;
                }
                BindMenu(strUserID);
            }
        }
        private void BindMenu(string strID)
        {
            BLL.SysManage.T_PUB_MENU bll = new BLL.SysManage.T_PUB_MENU();
            List<Model.SysManage.T_PUB_MENU> menuList = bll.GetUserMenuList(strID);
            StringBuilder strHtml = new StringBuilder();
            #region 获得一级菜单
            IEnumerable<Model.SysManage.T_PUB_MENU> pList = menuList.Where(p => p.PARENT_ID == 0);
            IEnumerable<Model.SysManage.T_PUB_MENU> nList;
            foreach (Model.SysManage.T_PUB_MENU item in pList)
            {
                strHtml.Append("<h1 class=\"type\">");
                strHtml.Append(" <a href=\"javascript:void(0)\">" + item.MENU_NAME + "</a></h1>");
                strHtml.Append("<div class=\"content\">");
                strHtml.Append("<table width=\"100%\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\">");
                strHtml.Append(" <tr>");
                strHtml.Append("<td>");
                strHtml.Append(" <img src=\"../Images/Login/menu_topline.gif\" width=\"182\" height=\"5\" />");
                strHtml.Append("</td>");
                strHtml.Append("</tr>");
                strHtml.Append("</table>");
                strHtml.Append("<ul class=\"MM\">");

                #region 加载二级菜单
                nList = menuList.Where(p => p.PARENT_ID == item.MENU_ID);
                foreach (Model.SysManage.T_PUB_MENU items in nList)
                {
                    strHtml.Append(string.Format(" <li><a href='right.aspx?urlNext={0}&Name={1}'", items.URL,items.MENU_NAME));
                    strHtml.Append(" target=\"main\">"+items.MENU_NAME+"</a></li>");
                }
                #endregion

                strHtml.Append("</ul>");
                strHtml.Append("</div>");
            }
            #endregion
            container.InnerHtml = strHtml.ToString();
        }
    }
}